import moment from 'moment';
import tracker from '../util/actionTracker';
import { visitEnd } from '../constant/events';

let appStartTime = 0;

export const appStartUse = (): void => {
  appStartTime = moment().unix();
};

export const appEndUse = (): void => {
  if (appStartTime === 0) return;

  const appEndTime = moment().unix();
  const duration = appEndTime - appStartTime;
  if (duration > 5) {
    appStartTime = 0;
    tracker.reportAction(visitEnd, {
      duration
    });
  }
};
